#ifndef __MUSIC_IF_HPP
#define __MUSIC_IF_HPP

#include "../lvgl/lvgl.h"
#include "music.hpp"

struct WAVHeader {
    char chunkID[4];
    uint32_t chunkSize;
    char format[4];
    char subchunk1ID[4];
    uint32_t subchunk1Size;
    uint16_t audioFormat;
    uint16_t numChannels;
    uint32_t sampleRate;
    uint32_t byteRate;
    uint16_t blockAlign;
    uint16_t bitsPerSample;
};

struct Data {
    char data[4];
    uint32_t dataSize;
};

// 音量接口
class AbstractVolume {
public:
    virtual void setVolume(uint8_t vol) = 0;
    virtual uint8_t getVolume() = 0;
};

// 喇叭音量
#define beep BeepVolume::getInstance()
class BeepVolume : public AbstractVolume {
private:
    uint8_t volume = 0;
    BeepVolume() = default;
public:
    static BeepVolume* getInstance() { static BeepVolume instance; return &instance; }
    void setVolume(uint8_t vol) override;
    uint8_t getVolume() override { return volume; };
};

// 耳机音量
#define phone PhoneVolume::getInstance()
class PhoneVolume : public AbstractVolume {
private:
    uint8_t volume = 0;
    PhoneVolume() = default;
public:
    static PhoneVolume* getInstance() { static PhoneVolume instance; return &instance; }
    void setVolume(uint8_t vol) override;
    uint8_t getVolume() override { return volume; };
};

// 开始播放音乐(打开文件后调用playMusic)
void startPlayMusic();

// 播放音乐 并不断调用回调函数
void playMusic();

// 调整播放进度 单位: s
void adjustTim(uint16_t sec);

// 加载文件夹下的所有文件
uint8_t loadFiles(CString folder = "0:/music/");

// 获取随机数
uint16_t getRand();

#endif
